package cn.shop.dys.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

import java.util.HashMap;
import java.util.Map;

import cn.shop.dys.R;
import cn.shop.dys.bean.OrderInfo;

public class SuccessPayActivity extends Activity implements View.OnClickListener {

    @ViewInject(R.id.iv_fanhuianniu)
    ImageView iv_fanhuianniu;
    @ViewInject(R.id.tv_order_number)
    TextView tv_order_number;
    @ViewInject(R.id.tv_pay_count)
    TextView tv_pay_count;
    @ViewInject(R.id.tv_pay_way)
    TextView tv_pay_way;
    @ViewInject(R.id.bt_go_shopping)
    Button bt_go_shopping;
    @ViewInject(R.id.bt_query_order)
    Button bt_query_order;
    private OrderInfo orderInfo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_success_pay);
        ViewUtils.inject(this);
        initView();
    }

    private void initView() {
        String json = getIntent().getStringExtra("mm");
        Log.d("test2",json);


//        json = {"orderInfo":{
//            "orderId":"096630", "paymentType":1, "price":450
//        },"response":"orderSubmit"}

        Gson gson = new Gson();
        Map paymentTypeMap = new HashMap();

        paymentTypeMap.put(0,"到付-现金");
        paymentTypeMap.put(1,"支付宝");
        paymentTypeMap.put(2,"微信");
        orderInfo = gson.fromJson(json, OrderInfo.class);
        tv_pay_count.setText("应付金额："+ orderInfo.getPrice());
        tv_order_number.setText("您的订单号："+ orderInfo.getOrderId());
        tv_pay_way.setText("支付方式："+paymentTypeMap.get(orderInfo.paymentType));
        iv_fanhuianniu.setOnClickListener(this);
        bt_go_shopping.setOnClickListener(this);
        bt_query_order.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_fanhuianniu:
                finish();
                break;

            case R.id.bt_go_shopping:
                //// TODO: 2016/4/23  跳转商品列表界面
                Intent intent1 = new Intent(this,MainActivity2.class);
                startActivity(intent1);
                break;
            case R.id.bt_query_order:
                /// TODO: 2016/4/23 跳转订单查询界面
                Intent intent2 = new Intent(this,UserIndentDetailActivity.class);
                intent2.putExtra("orderId",orderInfo.getOrderId());
                startActivity(intent2);
                break;
        }
    }


}
